package com.example.jjyu.controller;

import com.example.jjyu.entity.Coupon;
import com.example.jjyu.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.jjyu.service.CouponService;
@RestController
@RequestMapping("/api/v1/coupons")
public class CouponController {

    @Autowired
    private CouponService couponService;

    // 自动匹配优惠券
    @PostMapping("/auto-apply")
    public Result autoApplyCoupon(@RequestBody Coupon coupon) {
        Coupon appliedCoupon = couponService.autoApplyCoupon(coupon.getUserId(), coupon.getPlatform(), coupon.getCartAmount());
        if (appliedCoupon != null) {
            return Result.success(appliedCoupon);
        }
        return Result.error("未找到合适的优惠券");
    }

    // 优惠券提醒
    @GetMapping("/reminder")
    public Result getExpiringCoupons(@RequestParam String userId) {
        return Result.success(couponService.getExpiringCoupons(userId));
    }
}